package com.njrsrc.android.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.njrsrc.R;
import com.njrsrc.android.app.AppApplication;
import com.njrsrc.android.app.ArchivesActivity;
import com.njrsrc.android.app.FindJobActivity;
import com.njrsrc.android.app.HrLetterActivity;
import com.njrsrc.android.app.JobCollectActivity;
import com.njrsrc.android.app.JobFairActivity;
import com.njrsrc.android.app.LoginActivity;
import com.njrsrc.android.app.MainActivity;
import com.njrsrc.android.app.NewsActivity;
import com.njrsrc.android.app.SettingsActivity;

public final class MenuFragment extends Fragment {
	private RelativeLayout firstPage;
	private RelativeLayout message;
	private RelativeLayout findJob;
	private RelativeLayout jobFair;
	private RelativeLayout hrLetter;
	private RelativeLayout jobCollect;
	private RelativeLayout companyCollect;
	private RelativeLayout whoLookMe;
	private RelativeLayout applyRecord;
	private RelativeLayout archivesQuery;
	private RelativeLayout setting;
	private Handler mHandler = new Handler()
	{
		public void handleMessage(android.os.Message msg) 
		{};
	};
    public static MenuFragment newInstance() {
        return new MenuFragment();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_menu, container,false);
    }
    
    public OnClickListener listeners = new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.firstPage:
				Intent firstPageIntent = new Intent(getActivity(),MainActivity.class);
				firstPageIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				getActivity().startActivity(firstPageIntent);
				break;
			case R.id.message:
				Intent messageIntent = new Intent(getActivity(),NewsActivity.class);
				messageIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				getActivity().startActivity(messageIntent);
				break;
			case R.id.findJob:
				Intent findJobIntent = new Intent(getActivity(),FindJobActivity.class);
				findJobIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				getActivity().startActivity(findJobIntent);
				break;
			case R.id.jobFair:
				Intent jobFairIntent = new Intent(getActivity(),JobFairActivity.class);
				jobFairIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				getActivity().startActivity(jobFairIntent);
				break;
			case R.id.hrLetter:
				if (AppApplication.isLogin) {
					// 已登录
					Intent hrLetterIntent = new Intent();
					hrLetterIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					hrLetterIntent.setClass(getActivity(), HrLetterActivity.class);
					startActivity(hrLetterIntent);
				} else {
					Intent loginIntent = new Intent();
					loginIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					loginIntent.setClass(getActivity(), LoginActivity.class);
					startActivity(loginIntent);
				}
				break;
			case R.id.jobCollect:
				if (AppApplication.isLogin) {
					Intent jobCollectIntent = new Intent(getActivity(),JobCollectActivity.class);
					jobCollectIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					jobCollectIntent.putExtra("from", "collect");
					getActivity().startActivity(jobCollectIntent);
				}else
				{
					Intent loginIntent = new Intent();
					loginIntent.setClass(getActivity(), LoginActivity.class);
					startActivity(loginIntent);
				}
				
				break;
			case R.id.companyCollect:
				break;
			case R.id.whoLookMe:
	
				break;
			case R.id.applyRecord:
				if (AppApplication.isLogin)
				{
					Intent applyRecordIntent = new Intent(getActivity(),JobCollectActivity.class);
					applyRecordIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					applyRecordIntent.putExtra("from", "record");
					getActivity().startActivity(applyRecordIntent);
				}else
				{
					Intent loginIntent = new Intent();
					loginIntent.setClass(getActivity(), LoginActivity.class);
					startActivity(loginIntent);
				}
				
				break;
			case R.id.archivesQuery:
				// 档案查询
				if (AppApplication.isLogin) {
					// 已登录
					Intent archivesIntent = new Intent();
					archivesIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					archivesIntent.setClass(getActivity(), ArchivesActivity.class);
					startActivity(archivesIntent);
				} else {
					Intent loginIntent = new Intent();
					loginIntent.setClass(getActivity(), LoginActivity.class);
					startActivity(loginIntent);
				}
	
				break;
			case R.id.setting:
				// 设置
				Intent settingsIntent = new Intent();
				settingsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				settingsIntent.setClass(getActivity(), SettingsActivity.class);
				startActivity(settingsIntent);
				break;

			default:
				break;
			}
		}
	};
    
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
    	super.onActivityCreated(savedInstanceState);
    	firstPage = (RelativeLayout) getActivity().findViewById(R.id.firstPage);
    	message = (RelativeLayout) getActivity().findViewById(R.id.message);
    	findJob = (RelativeLayout) getActivity().findViewById(R.id.findJob);
    	jobFair = (RelativeLayout) getActivity().findViewById(R.id.jobFair);
    	hrLetter = (RelativeLayout) getActivity().findViewById(R.id.hrLetter);
    	jobCollect = (RelativeLayout) getActivity().findViewById(R.id.jobCollect);
    	companyCollect = (RelativeLayout) getActivity().findViewById(R.id.companyCollect);
    	whoLookMe = (RelativeLayout) getActivity().findViewById(R.id.whoLookMe);
    	applyRecord = (RelativeLayout) getActivity().findViewById(R.id.applyRecord);
    	archivesQuery = (RelativeLayout) getActivity().findViewById(R.id.archivesQuery);
    	setting = (RelativeLayout) getActivity().findViewById(R.id.setting);
    	
    	firstPage.setOnClickListener(listeners);
    	message.setOnClickListener(listeners);
    	findJob.setOnClickListener(listeners);
    	jobFair.setOnClickListener(listeners);
    	hrLetter.setOnClickListener(listeners);
    	jobCollect.setOnClickListener(listeners);
    	companyCollect.setOnClickListener(listeners);
    	whoLookMe.setOnClickListener(listeners);
    	applyRecord.setOnClickListener(listeners);
    	archivesQuery.setOnClickListener(listeners);
    	setting.setOnClickListener(listeners);
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }
}
